import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/login',
    meta: {
      title: 'login'
    },
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '/pay-tips',
    name: 'payTips',
    component: () => import('@/views/errorPage/payTips'),
    meta: {
      title: 'payTips'
    }
  },
  {
    path: '/pay-status',
    meta: {
      title: 'paymentStatus'
    },
    name: 'paymentStatus',
    component: () => import('@/views/errorLog/paymentStatus'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', navShow: true, copyShow: true }
      }
    ]
  }
]

export default new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/goods',
    component: Layout,
    meta: { title: 'goods', icon: 'goodsIcon' },
    children: [
      { path: 'goods-index', component: _import('goods/goodsList/index'), name: 'goods-index', meta: { navShow: true, copyShow: true, title: 'goodsList' }},
      { path: 'goods-detail', component: _import('goods/goodsDetail/index'), name: 'goods-detail', meta: { copyShow: true, title: 'goodsDetail' }}
    ]
  },
  {
    path: '/shopCar',
    component: Layout,
    meta: { title: 'shopCar', icon: 'shopCar' },
    children: [
      { path: 'shop-car', component: _import('shopCar/index'), name: 'shop-car', meta: { navShow: true, copyShow: true, title: 'shopCar' }},
      { path: 'shop-settlement', component: _import('shopCar/settlement/index'), name: 'shop-settlement', meta: { copyShow: true, title: 'settlement' }},
      { path: 'add-order-success', component: _import('shopCar/success/index'), name: 'add-order-success', meta: { title: 'success' }}
    ]
  },
  {
    path: '/order',
    component: Layout,
    meta: { title: 'order' },
    children: [
      { path: 'order-list', component: _import('order/orderList/index'), name: 'order-list', meta: { title: 'orderList' }},
      { path: 'order-detail', component: _import('order/orderDetail/index'), name: 'order-detail', meta: { title: 'orderDetail' }}
    ]
  },
  {
    path: '/refund',
    component: Layout,
    meta: { title: 'refund' },
    children: [
      { path: 'refund-list', component: _import('refund/refundList/index'), name: 'refund-list', meta: { title: 'refundList' }},
      { path: 'refund-add', component: _import('refund/addRefund/index'), name: 'refund-add', meta: { title: 'refundAdd' }},
      { path: 'refund-detail', component: _import('refund/refundDetail/index'), name: 'refund-detail', meta: { title: 'refundDetail' }}
    ]
  },
  {
    path: '/userCenter',
    component: Layout,
    meta: { title: 'userCenter' },
    children: [
      { path: 'user-center', component: _import('userCenter/index'), name: 'user-center', meta: { navShow: true, copyShow: true, title: 'userCenter' }},
      { path: 'user-address', component: _import('userCenter/userAddress/index'), name: 'user-address', meta: { title: 'userAddress' }},
      { path: 'add-address', component: _import('userCenter/userAddress/addAddress/index'), name: 'add-address', meta: { title: 'addAddress' }},
      { path: 'edit-address', component: _import('userCenter/userAddress/editAddress/index'), name: 'edit-address', meta: { title: 'editAddress' }},
      { path: 'user-info', component: _import('userCenter/userInfo/index'), name: 'user-info', meta: { title: 'userInfo' }},
      { path: 'edit-info', component: _import('userCenter/userInfo/editInfo/index'), name: 'edit-info', meta: { title: 'editInfo' }},
      { path: 'user-account', component: _import('userCenter/userAccount/index'), name: 'user-account', meta: { title: 'userAccount' }}
    ]
  },
  {
    path: '/icon',
    component: Layout,
    meta: {},
    children: [{
      path: 'index',
      component: _import('svg-icons/index'),
      name: 'icons',
      meta: { title: 'icons', icon: 'icon', noCache: true }
    }]
  },
  { path: '*', redirect: '/404', hidden: true }
]
